<template>
<div class="sys-info" v-rs-resize="onResize">
    <div class="rs-toolbar">
        <el-button-group>
            <el-button type="primary" size="small" icon="rs-icon-add-circle-fill" @click="loadSysInfo">刷新系统信息</el-button>
        </el-button-group>
    </div>
    <RsWrap :top="36" :scrollY="true">
        <div class="content" v-if="data">
        <el-row>
            <el-col :span="24">
                <span class="title">JIT编译器：</span><span class="text">{{data.compilationInfo.name}}</span>
                <span class="title">编译时间：</span><span class="text">{{data.compilationInfo.time}}</span>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <span class="title">已加载类总数：</span><span class="text">{{data.classLoadInfo.totalLoadedCount}}</span>
                <span class="title">已加载当前类：</span><span class="text">{{data.classLoadInfo.loadedCount}}</span>
                <span class="title">已卸载类总数：</span><span class="text">{{data.classLoadInfo.unLoadedCount}}</span>
            </el-col>
        </el-row>
        <el-row>
             <el-col :span="24">
                <span class="title">启动参数：</span><span class="text">{{inputArguments}}</span>
            </el-col>
            <el-col :span="24">
                <span class="title">仍活动的线程总数：</span><span class="text">{{data.threadInfo.activeCount}}</span>
                <span class="title">峰值线程总数：</span><span class="text">{{data.threadInfo.peekCount}}</span>
                <span class="title">守护线程总数：</span><span class="text">{{data.threadInfo.daemonCount}}</span>
                <span class="title">死锁线程总数：</span><span class="text">{{data.threadInfo.deadCount}}</span>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <span class="title">jvm参数，进程号：{{data.runtimeInfo.name}}</span>
            </el-col>
            <el-table style="width:850px" :data="data.vmList" border size="small" highlight-current-row :show-header="false">
                    <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
                    <el-table-column prop="jvmName" label="jvm规范信息" width="130" align="left" header-align="center"></el-table-column>
                    <el-table-column prop="jvmValue" label="jvm规范信息值" width="240" align="left" header-align="center"></el-table-column>
                    <el-table-column prop="vmName" label="jvm信息" width="130" align="left" header-align="center"></el-table-column>
                    <el-table-column prop="vmValue" label="jvm信息值" align="left" header-align="center"></el-table-column>
            </el-table>
        </el-row>
        <el-row>
            <el-col :span="24">
                <span class="title">内存区参数：</span>
            </el-col>
        </el-row>
        <el-table style="width:750px" :data="data.memoryList" border size="small" highlight-current-row>
                <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
                <el-table-column prop="name" label="内存区名称" width="220" align="left" header-align="center"></el-table-column>
                <el-table-column prop="init" label="最大（上限）" width="150" align="right" header-align="center"></el-table-column>
                <el-table-column prop="max" label="已提交大小" width="150" align="right" header-align="center"></el-table-column>
                <el-table-column prop="used" label="已用大小" align="right" header-align="center"></el-table-column>
        </el-table>
        <el-row>
            <el-col :span="24">
                <span class="title">类路径：</span>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <span class="text">{{data.runtimeInfo.classPath}}</span>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <span class="title">启动路径：</span>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <span class="text">{{data.runtimeInfo.bootClassPath}}</span>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <span class="title">库路径：</span>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <span class="text">{{data.runtimeInfo.libraryPath}}</span>
            </el-col>
        </el-row>
        </div>
    </RsWrap>
</div>
</template>
<script>
import tips from '../../mixin/tips'
export default {
    name:'InfoPage',
    components:{},
    mixins:[tips],
    data(){
        return {
            tableHeight:0,
            data:null
        }
    },
    created(){
        this.loadSysInfo();
    },
    computed:{
        inputArguments(){
            var result = "";
            if(!this.data) return ''
             for(var v of this.data.runtimeInfo.inputArguments ){
                result += v + ' ';
            }
            return result;
        }
    },
    methods:{
        onResize(obj){
            //console.log(this)
            this.tableHeight = obj.height;
        },
        loadSysInfo(){
            this.loading = true;
            this.$req({
                url: '/log/info',
                method: 'post',
                data:{}
            })
            .then(response => {
                this.loading = false;
                const resp = response.data;
                if( resp.error_code == 0 ){
                    
                    const vmList = [];
                    const data = this.data = resp.data;                    
                    this.data.vmList = vmList;
                    vmList.push({
                        jvmName:'jvm规范名称',
                        jvmValue:data.runtimeInfo.specName,
                        vmName:'jvm名称',
                        vmValue:data.runtimeInfo.vmName
                    })
                    vmList.push({
                        jvmName:'jvm规范运营商',
                        jvmValue:data.runtimeInfo.specVendor,
                        vmName:'jvm运营商',
                        vmValue:data.runtimeInfo.vmVendor,
                    })
                    vmList.push({
                        jvmName:'jvm规范版本',
                        jvmValue:data.runtimeInfo.specVersion,
                        vmName:'jvm版本',
                        vmValue:data.runtimeInfo.vmVersion,
                    })
                    vmList.push({
                        jvmName:'jvm启动时间',
                        jvmValue:data.runtimeInfo.startTime,
                        vmName:'jvm运行时间',
                        vmValue:data.runtimeInfo.uptime,
                    })
                    console.log(data)
                }else{
                    this.showError("操作失败！");
                }
            }).catch(error => {
                this.loading = false;
            });
        }
    }
}
</script>